home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / printcmd.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  52KB  |  2,000 lines

  1. /* Print values for GNU debugger GDB.
  2.    Copyright (C) 1986-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include "defs.h"
  23. #include "param.h"
  24. #include "frame.h"
  25. #include "symtab.h"
  26. #include "value.h"
  27. #include "language.h"
  28. #include "expression.h"
  29. #include "gdbcore.h"
  30. #include "gdbcmd.h"
  31. #include "target.h"
  32.  
  33. extern int asm_demangle;    /* Whether to demangle syms in asm printouts */
  34. extern int addressprint;    /* Whether to print hex addresses in HLL " */
  35.  
  36. extern struct block *get_current_block ();
  37.  
  38. static void print_frame_nameless_args ();
  39.  
  40. struct format_data
  41. {
  42.   int count;
  43.   char format;
  44.   char size;
  45. };
  46.  
  47. /* Last specified output format.  */
  48.  
  49. static char last_format = 'x';
  50.  
  51. /* Last specified examination size.  'b', 'h', 'w' or `q'.  */
  52.  
  53. static char last_size = 'w';
  54.  
  55. /* Default address to examine next.  */
  56.  
  57. static CORE_ADDR next_address;
  58.  
  59. /* Last address examined.  */
  60.  
  61. static CORE_ADDR last_examine_address;
  62.  
  63. /* Contents of last address examined.
  64.    This is not valid past the end of the `x' command!  */
  65.  
  66. static value last_examine_value;
  67.  
  68. /* Number of auto-display expression currently being displayed.
  69.    So that we can deleted it if we get an error or a signal within it.
  70.    -1 when not doing one.  */
  71.  
  72. int current_display_number;
  73.  
  74. /* Flag to low-level print routines that this value is being printed
  75.    in an epoch window.  We'd like to pass this as a parameter, but
  76.    every routine would need to take it.  Perhaps we can encapsulate
  77.    this in the I/O stream once we have GNU stdio. */
  78.  
  79. int inspect_it = 0;
  80.  
  81. static void do_one_display ();
  82.  
  83. void do_displays ();
  84. void print_scalar_formatted ();
  85.  
  86.  
  87. /* Decode a format specification.  *STRING_PTR should point to it.
  88.    OFORMAT and OSIZE are used as defaults for the format and size
  89.    if none are given in the format specification.
  90.    If OSIZE is zero, then the size field of the returned value
  91.    should be set only if a size is explicitly specified by the
  92.    user.
  93.    The structure returned describes all the data
  94.    found in the specification.  In addition, *STRING_PTR is advanced
  95.    past the specification and past all whitespace following it.  */
  96.  
  97. struct format_data
  98. decode_format (string_ptr, oformat, osize)
  99.      char **string_ptr;
  100.      char oformat;
  101.      char osize;
  102. {
  103.   struct format_data val;
  104.   register char *p = *string_ptr;
  105.  
  106.   val.format = '?';
  107.   val.size = '?';
  108.   val.count = 1;
  109.  
  110.   if (*p >= '0' && *p <= '9')
  111.     val.count = atoi (p);
  112.   while (*p >= '0' && *p <= '9') p++;
  113.  
  114.   /* Now process size or format letters that follow.  */
  115.  
  116.   while (1)
  117.     {
  118.       if (*p == 'b' || *p == 'h' || *p == 'w' || *p == 'g')
  119.     val.size = *p++;
  120. #ifdef LONG_LONG
  121.       else if (*p == 'l')
  122.     {
  123.       val.size = 'g';
  124.       p++;
  125.     }
  126. #endif
  127.       else if (*p >= 'a' && *p <= 'z')
  128.     val.format = *p++;
  129.       else
  130.     break;
  131.     }
  132.  
  133. #ifndef LONG_LONG
  134.   /* Make sure 'g' size is not used on integer types.
  135.      Well, actually, we can handle hex.  */
  136.   if (val.size == 'g' && val.format != 'f' && val.format != 'x')
  137.     val.size = 'w';
  138. #endif
  139.  
  140.   while (*p == ' ' || *p == '\t') p++;
  141.   *string_ptr = p;
  142.  
  143.   /* Set defaults for format and size if not specified.  */
  144.   if (val.format == '?')
  145.     {
  146.       if (val.size == '?')
  147.     {
  148.       /* Neither has been specified.  */
  149.       val.format = oformat;
  150.       val.size = osize;
  151.     }
  152.       else
  153.     /* If a size is specified, any format makes a reasonable
  154.        default except 'i'.  */
  155.     val.format = oformat == 'i' ? 'x' : oformat;
  156.     }
  157.   else if (val.size == '?')
  158.     switch (val.format)
  159.       {
  160.       case 'a':
  161.       case 's':
  162.     /* Addresses must be words.  */
  163.     val.size = osize ? 'w' : osize;
  164.     break;
  165.       case 'f':
  166.     /* Floating point has to be word or giantword.  */
  167.     if (osize == 'w' || osize == 'g')
  168.       val.size = osize;
  169.     else
  170.       /* Default it to giantword if the last used size is not
  171.          appropriate.  */
  172.       val.size = osize ? 'g' : osize;
  173.     break;
  174.       case 'c':
  175.     /* Characters default to one byte.  */
  176.     val.size = osize ? 'b' : osize;
  177.     break;
  178.       default:
  179.     /* The default is the size most recently specified.  */
  180.     val.size = osize;
  181.       }
  182.  
  183.   return val;
  184. }
  185.  
  186. /* Print value VAL on stdout according to FORMAT, a letter or 0.
  187.    Do not end with a newline.
  188.    0 means print VAL according to its own type.
  189.    SIZE is the letter for the size of datum being printed.
  190.    This is used to pad hex numbers so they line up.  */
  191.  
  192. static void
  193. print_formatted (val, format, size)
  194.      register value val;
  195.      register char format;
  196.      char size;
  197. {
  198.   int len = TYPE_LENGTH (VALUE_TYPE (val));
  199.  
  200.   if (VALUE_LVAL (val) == lval_memory)
  201.     next_address = VALUE_ADDRESS (val) + len;
  202.  
  203.   switch (format)
  204.     {
  205.     case 's':
  206.       next_address = VALUE_ADDRESS (val)
  207.     + value_print (value_addr (val), stdout, format, Val_pretty_default);
  208.       break;
  209.  
  210.     case 'i':
  211.       wrap_here ("");    /* Force output out, print_insn not using _filtered */
  212.       next_address = VALUE_ADDRESS (val)
  213.     + print_insn (VALUE_ADDRESS (val), stdout);
  214.       break;
  215.  
  216.     default:
  217.       if (format == 0
  218.       || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_ARRAY
  219.       || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_STRUCT
  220.       || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_UNION
  221.       || VALUE_REPEATED (val))
  222.     value_print (val, stdout, format, Val_pretty_default);
  223.       else
  224.     print_scalar_formatted (VALUE_CONTENTS (val), VALUE_TYPE (val),
  225.                 format, size, stdout);
  226.     }
  227. }
  228.  
  229. /* Print a scalar of data of type TYPE, pointed to in GDB by VALADDR,
  230.    according to letters FORMAT and SIZE on STREAM.
  231.    FORMAT may not be zero.  Formats s and i are not supported at this level.
  232.  
  233.    This is how the elements of an array or structure are printed
  234.    with a format.  */
  235.  
  236. void
  237. print_scalar_formatted (valaddr, type, format, size, stream)
  238.      char *valaddr;
  239.      struct type *type;
  240.      char format;
  241.      int size;
  242.      FILE *stream;
  243. {
  244.   LONGEST val_long;
  245.   int len = TYPE_LENGTH (type);
  246.  
  247.   if (size == 'g' && sizeof (LONGEST) < 8
  248.       && format == 'x')
  249.     {
  250.       /* ok, we're going to have to get fancy here.  Assumption: a
  251.          long is four bytes.  FIXME.  */
  252.       unsigned long v1, v2, tmp;
  253.  
  254.       v1 = unpack_long (builtin_type_long, valaddr);
  255.       v2 = unpack_long (builtin_type_long, valaddr + 4);
  256.  
  257. #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
  258.       /* Swap the two for printing */
  259.       tmp = v1;
  260.       v1 = v2;
  261.       v2 = tmp;
  262. #endif
  263.   
  264.       switch (format)
  265.     {
  266.     case 'x':
  267.       fprintf_filtered (stream, local_hex_format_custom("08x%08"), v1, v2);
  268.       break;
  269.     default:
  270.       error ("Output size \"g\" unimplemented for format \"%c\".",
  271.          format);
  272.     }
  273.       return;
  274.     }
  275.       
  276.   val_long = unpack_long (type, valaddr);
  277.  
  278.   /* If value is unsigned, truncate it in case negative.  */
  279.   if (format != 'd')
  280.     {
  281.       if (len == sizeof (char))
  282.     val_long &= (1 << 8 * sizeof(char)) - 1;
  283.       else if (len == sizeof (short))
  284.     val_long &= (1 << 8 * sizeof(short)) - 1;
  285.       else if (len == sizeof (long))
  286.     val_long &= (unsigned long) - 1;
  287.     }
  288.  
  289.   switch (format)
  290.     {
  291.     case 'x':
  292.       if (!size)
  293.     {
  294.       /* no size specified, like in print.  Print varying # of digits. */
  295. #if defined (LONG_LONG)
  296.       fprintf_filtered (stream, local_hex_format_custom("ll"), val_long);
  297. #else /* not LONG_LONG.  */
  298.       fprintf_filtered (stream, local_hex_format_custom("l"), val_long);
  299. #endif /* not LONG_LONG.  */
  300.     }
  301.       else
  302. #if defined (LONG_LONG)
  303.       switch (size)
  304.     {
  305.     case 'b':
  306.       fprintf_filtered (stream, local_hex_format_custom("02ll"), val_long);
  307.       break;
  308.     case 'h':
  309.       fprintf_filtered (stream, local_hex_format_custom("04ll"), val_long);
  310.       break;
  311.     case 'w':
  312.       fprintf_filtered (stream, local_hex_format_custom("08ll"), val_long);
  313.       break;
  314.     case 'g':
  315.       fprintf_filtered (stream, local_hex_format_custom("016ll"), val_long);
  316.       break;
  317.     default:
  318.       error ("Undefined output size \"%c\".", size);
  319.     }
  320. #else /* not LONG_LONG.  */
  321.       switch (size)
  322.     {
  323.     case 'b':
  324.       fprintf_filtered (stream, local_hex_format_custom("02"), val_long);
  325.       break;
  326.     case 'h':
  327.       fprintf_filtered (stream, local_hex_format_custom("04"), val_long);
  328.       break;
  329.     case 'w':
  330.       fprintf_filtered (stream, local_hex_format_custom("08"), val_long);
  331.       break;
  332.     case 'g':
  333.       fprintf_filtered (stream, local_hex_format_custom("016"), val_long);
  334.       break;
  335.     default:
  336.       error ("Undefined output size \"%c\".", size);
  337.     }
  338. #endif /* not LONG_LONG */
  339.       break;
  340.  
  341.     case 'd':
  342. #ifdef LONG_LONG
  343.       fprintf_filtered (stream, "%lld", val_long);
  344. #else
  345.       fprintf_filtered (stream, "%d", val_long);
  346. #endif
  347.       break;
  348.  
  349.     case 'u':
  350. #ifdef LONG_LONG
  351.       fprintf_filtered (stream, "%llu", val_long);
  352. #else
  353.       fprintf_filtered (stream, "%u", val_long);
  354. #endif
  355.       break;
  356.  
  357.     case 'o':
  358.       if (val_long)
  359. #ifdef LONG_LONG
  360.     fprintf_filtered (stream, local_octal_format_custom("ll"), val_long);
  361. #else
  362.     fprintf_filtered (stream, local_octal_format(), val_long);
  363. #endif
  364.       else
  365.     fprintf_filtered (stream, "0");
  366.       break;
  367.  
  368.     case 'a':
  369.       print_address (unpack_pointer (type, valaddr), stream);
  370.       break;
  371.  
  372.     case 'c':
  373.       value_print (value_from_longest (builtin_type_char, val_long), stream, 0,
  374.            Val_pretty_default);
  375.       break;
  376.  
  377.     case 'f':
  378.       if (len == sizeof (float))
  379.     type = builtin_type_float;
  380.       else if (len == sizeof (double))
  381.     type = builtin_type_double;
  382.       print_floating (valaddr, type, stream);
  383.       break;
  384.  
  385.     case 0:
  386.       abort ();
  387.  
  388.     case 't':
  389.       /* Binary; 't' stands for "two".  */
  390.       {
  391.         char bits[8*(sizeof val_long) + 1];
  392.     char *cp = bits;
  393.     int width;
  394.  
  395.         if (!size)
  396.       width = 8*(sizeof val_long);
  397.         else
  398.           switch (size)
  399.         {
  400.         case 'b':
  401.           width = 8;
  402.           break;
  403.         case 'h':
  404.           width = 16;
  405.           break;
  406.         case 'w':
  407.           width = 32;
  408.           break;
  409.         case 'g':
  410.           width = 64;
  411.           break;
  412.         default:
  413.           error ("Undefined output size \"%c\".", size);
  414.         }
  415.  
  416.         bits[width] = '\0';
  417.         while (width-- > 0)
  418.           {
  419.             bits[width] = (val_long & 1) ? '1' : '0';
  420.             val_long >>= 1;
  421.           }
  422.     if (!size)
  423.       {
  424.         while (*cp && *cp == '0')
  425.           cp++;
  426.         if (*cp == '\0')
  427.           cp--;
  428.       }
  429.         fprintf_filtered (stream, cp);
  430.       }
  431.       break;
  432.  
  433.     default:
  434.       error ("Undefined output format \"%c\".", format);
  435.     }
  436. }
  437.  
  438. /* Specify default address for `x' command.
  439.    `info lines' uses this.  */
  440.  
  441. void
  442. set_next_address (addr)
  443.      CORE_ADDR addr;
  444. {
  445.   next_address = addr;
  446.  
  447.   /* Make address available to the user as $_.  */
  448.   set_internalvar (lookup_internalvar ("_"),
  449.            value_from_longest (lookup_pointer_type (builtin_type_void),
  450.                     (LONGEST) addr));
  451. }
  452.  
  453. /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
  454.    after LEADIN.  Print nothing if no symbolic name is found nearby.
  455.    DO_DEMANGLE controls whether to print a symbol in its native "raw" form,
  456.    or to interpret it as a possible C++ name and convert it back to source
  457.    form. */
  458.  
  459. void
  460. print_address_symbolic (addr, stream, do_demangle, leadin)
  461.      CORE_ADDR addr;
  462.      FILE *stream;
  463.      int do_demangle;
  464.      char *leadin;
  465. {
  466.   int name_location;
  467.   register int i = find_pc_misc_function (addr);
  468.  
  469.   /* If nothing comes out, don't print anything symbolic.  */
  470.   
  471.   if (i < 0)
  472.     return;
  473.  
  474.   fputs_filtered (leadin, stream);
  475.   fputs_filtered ("<", stream);
  476.   if (do_demangle)
  477.     fputs_demangled (misc_function_vector[i].name, stream, 1);
  478.   else
  479.     fputs_filtered (misc_function_vector[i].name, stream);
  480.   name_location = misc_function_vector[i].address;
  481.   if (addr - name_location)
  482.     fprintf_filtered (stream, "+%d>", addr - name_location);
  483.   else
  484.     fputs_filtered (">", stream);
  485. }
  486.  
  487. /* Print address ADDR symbolically on STREAM.
  488.    First print it as a number.  Then perhaps print
  489.    <SYMBOL + OFFSET> after the number.  */
  490.  
  491. void
  492. print_address (addr, stream)
  493.      CORE_ADDR addr;
  494.      FILE *stream;
  495. {
  496.   fprintf_filtered (stream, local_hex_format(), addr);
  497.   print_address_symbolic (addr, stream, asm_demangle, " ");
  498. }
  499.  
  500. /* Print address ADDR symbolically on STREAM.  Parameter DEMANGLE
  501.    controls whether to print the symbolic name "raw" or demangled.
  502.    Global setting "addressprint" controls whether to print hex address
  503.    or not.  */
  504.  
  505. void
  506. print_address_demangle (addr, stream, do_demangle)
  507.      CORE_ADDR addr;
  508.      FILE *stream;
  509.      int do_demangle;
  510. {
  511.   if (addr == 0) {
  512.     fprintf_filtered (stream, "0");
  513.   } else if (addressprint) {
  514.     fprintf_filtered (stream, local_hex_format(), addr);
  515.     print_address_symbolic (addr, stream, do_demangle, " ");
  516.   } else {
  517.     print_address_symbolic (addr, stream, do_demangle, "");
  518.   }
  519. }
  520.  
  521.  
  522. /* Examine data at address ADDR in format FMT.
  523.    Fetch it from memory and print on stdout.  */
  524.  
  525. static void
  526. do_examine (fmt, addr)
  527.      struct format_data fmt;
  528.      CORE_ADDR addr;
  529. {
  530.   register char format = 0;
  531.   register char size;
  532.   register int count = 1;
  533.   struct type *val_type;
  534.   register int i;
  535.   register int maxelts;
  536.  
  537.   format = fmt.format;
  538.   size = fmt.size;
  539.   count = fmt.count;
  540.   next_address = addr;
  541.  
  542.   /* String or instruction format implies fetch single bytes
  543.      regardless of the specified size.  */
  544.   if (format == 's' || format == 'i')
  545.     size = 'b';
  546.  
  547.   if (size == 'b')
  548.     val_type = builtin_type_char;
  549.   else if (size == 'h')
  550.     val_type = builtin_type_short;
  551.   else if (size == 'w')
  552.     val_type = builtin_type_long;
  553.   else if (size == 'g')
  554. #ifndef LONG_LONG
  555.     val_type = builtin_type_double;
  556. #else
  557.     val_type = builtin_type_long_long;
  558. #endif
  559.  
  560.   maxelts = 8;
  561.   if (size == 'w')
  562.     maxelts = 4;
  563.   if (size == 'g')
  564.     maxelts = 2;
  565.   if (format == 's' || format == 'i')
  566.     maxelts = 1;
  567.  
  568.   /* Print as many objects as specified in COUNT, at most maxelts per line,
  569.      with the address of the next one at the start of each line.  */
  570.  
  571.   while (count > 0)
  572.     {
  573.       print_address (next_address, stdout);
  574.       printf_filtered (":");
  575.       for (i = maxelts;
  576.        i > 0 && count > 0;
  577.        i--, count--)
  578.     {
  579.       printf_filtered ("\t");
  580.       /* Note that print_formatted sets next_address for the next
  581.          object.  */
  582.       last_examine_address = next_address;
  583.       last_examine_value = value_at (val_type, next_address);
  584.       print_formatted (last_examine_value, format, size);
  585.     }
  586.       printf_filtered ("\n");
  587.       fflush (stdout);
  588.     }
  589. }
  590.  
  591. static void
  592. validate_format (fmt, cmdname)
  593.      struct format_data fmt;
  594.      char *cmdname;
  595. {
  596.   if (fmt.size != 0)
  597.     error ("Size letters are meaningless in \"%s\" command.", cmdname);
  598.   if (fmt.count != 1)
  599.     error ("Item count other than 1 is meaningless in \"%s\" command.",
  600.        cmdname);
  601.   if (fmt.format == 'i' || fmt.format == 's')
  602.     error ("Format letter \"%c\" is meaningless in \"%s\" command.",
  603.        fmt.format, cmdname);
  604. }
  605.  
  606. static void
  607. print_command_1 (exp, inspect, voidprint)
  608.      char *exp;
  609.      int inspect;
  610.      int voidprint;
  611. {
  612.   struct expression *expr;
  613.   register struct cleanup *old_chain = 0;
  614.   register char format = 0;
  615.   register value val;
  616.   struct format_data fmt;
  617.   int cleanup = 0;
  618.  
  619.   /* Pass inspect flag to the rest of the print routines in a global (sigh). */
  620.   inspect_it = inspect;
  621.  
  622.   if (exp && *exp == '/')
  623.     {
  624.       exp++;
  625.       fmt = decode_format (&exp, last_format, 0);
  626.       validate_format (fmt, "print");
  627.       last_format = format = fmt.format;
  628.     }
  629.   else
  630.     {
  631.       fmt.count = 1;
  632.       fmt.format = 0;
  633.       fmt.size = 0;
  634.     }
  635.  
  636.   if (exp && *exp)
  637.     {
  638.       extern int objectprint;
  639.       struct type *type;
  640.       expr = parse_expression (exp);
  641.       old_chain = make_cleanup (free_current_contents, &expr);
  642.       cleanup = 1;
  643.       val = evaluate_expression (expr);
  644.  
  645.       /* C++: figure out what type we actually want to print it as.  */
  646.       type = VALUE_TYPE (val);
  647.  
  648.       if (objectprint
  649.       && (TYPE_CODE (type) == TYPE_CODE_PTR
  650.           || TYPE_CODE (type) == TYPE_CODE_REF)
  651.       && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)
  652.     {
  653.       value v;
  654.  
  655.       v = value_from_vtable_info (val, TYPE_TARGET_TYPE (type));
  656.       if (v != 0)
  657.         {
  658.           val = v;
  659.           type = VALUE_TYPE (val);
  660.         }
  661.     }
  662.     }
  663.   else
  664.     val = access_value_history (0);
  665.  
  666.   if (voidprint || (val && VALUE_TYPE (val) &&
  667.                     TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_VOID))
  668.     {
  669.       int histindex = record_latest_value (val);
  670.  
  671.       if (inspect)
  672.     printf ("\031(gdb-makebuffer \"%s\"  %d '(\"", exp, histindex);
  673.       else
  674.     if (histindex >= 0) printf_filtered ("$%d = ", histindex);
  675.  
  676.       print_formatted (val, format, fmt.size);
  677.       printf_filtered ("\n");
  678.       if (inspect)
  679.     printf("\") )\030");
  680.     }
  681.  
  682.   if (cleanup)
  683.     do_cleanups (old_chain);
  684.   inspect_it = 0;    /* Reset print routines to normal */
  685. }
  686.  
  687. /* ARGSUSED */
  688. void
  689. print_command (exp, from_tty)
  690.      char *exp;
  691.      int from_tty;
  692. {
  693.   print_command_1 (exp, 0, 1);
  694. }
  695.  
  696. /* Same as print, except in epoch, it gets its own window */
  697. /* ARGSUSED */
  698. static void
  699. inspect_command (exp, from_tty)
  700.      char *exp;
  701.      int from_tty;
  702. {
  703.   extern int epoch_interface;
  704.  
  705.   print_command_1 (exp, epoch_interface, 1);
  706. }
  707.  
  708. /* Same as print, except it doesn't print void results. */
  709. /* ARGSUSED */
  710. static void
  711. call_command (exp, from_tty)
  712.      char *exp;
  713.      int from_tty;
  714. {
  715.   print_command_1 (exp, 0, 0);
  716. }
  717.  
  718. /* ARGSUSED */
  719. static void
  720. output_command (exp, from_tty)
  721.      char *exp;
  722.      int from_tty;
  723. {
  724.   struct expression *expr;
  725.   register struct cleanup *old_chain;
  726.   register char format = 0;
  727.   register value val;
  728.   struct format_data fmt;
  729.  
  730.   if (exp && *exp == '/')
  731.     {
  732.       exp++;
  733.       fmt = decode_format (&exp, 0, 0);
  734.       validate_format (fmt, "print");
  735.       format = fmt.format;
  736.     }
  737.  
  738.   expr = parse_expression (exp);
  739.   old_chain = make_cleanup (free_current_contents, &expr);
  740.  
  741.   val = evaluate_expression (expr);
  742.  
  743.   print_formatted (val, format, fmt.size);
  744.  
  745.   do_cleanups (old_chain);
  746. }
  747.  
  748. /* ARGSUSED */
  749. static void
  750. set_command (exp, from_tty)
  751.      char *exp;
  752.      int from_tty;
  753. {
  754.   struct expression *expr = parse_expression (exp);
  755.   register struct cleanup *old_chain
  756.     = make_cleanup (free_current_contents, &expr);
  757.   evaluate_expression (expr);
  758.   do_cleanups (old_chain);
  759. }
  760.  
  761. /* ARGSUSED */
  762. static void
  763. address_info (exp, from_tty)
  764.      char *exp;
  765.      int from_tty;
  766. {
  767.   register struct symbol *sym;
  768.   register long val;
  769.   int is_a_field_of_this;    /* C++: lookup_symbol sets this to nonzero
  770.                    if exp is a field of `this'. */
  771.  
  772.   if (exp == 0)
  773.     error ("Argument required.");
  774.  
  775.   sym = lookup_symbol (exp, get_selected_block (), VAR_NAMESPACE, 
  776.                &is_a_field_of_this, (struct symtab **)NULL);
  777.   if (sym == 0)
  778.     {
  779.       register int i;
  780.  
  781.       if (is_a_field_of_this)
  782.     {
  783.       printf ("Symbol \"%s\" is a field of the local class variable `this'\n", exp);
  784.       return;
  785.     }
  786.  
  787.       for (i = 0; i < misc_function_count; i++)
  788.     if (!strcmp (misc_function_vector[i].name, exp))
  789.       break;
  790.  
  791.       if (i < misc_function_count)
  792.     printf ("Symbol \"%s\" is at %s in a file compiled without debugging.\n",
  793.         exp, local_hex_string(misc_function_vector[i].address));
  794.       else
  795.     error ("No symbol \"%s\" in current context.", exp);
  796.       return;
  797.     }
  798.  
  799.   printf ("Symbol \"%s\" is ", SYMBOL_NAME (sym));
  800.   val = SYMBOL_VALUE (sym);
  801.  
  802.   switch (SYMBOL_CLASS (sym))
  803.     {
  804.     case LOC_CONST:
  805.     case LOC_CONST_BYTES:
  806.       printf ("constant");
  807.       break;
  808.  
  809.     case LOC_LABEL:
  810.       printf ("a label at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
  811.       break;
  812.  
  813.     case LOC_REGISTER:
  814.       printf ("a variable in register %s", reg_names[val]);
  815.       break;
  816.  
  817.     case LOC_STATIC:
  818.       printf ("static storage at address %s", local_hex_string(SYMBOL_VALUE_ADDRESS (sym)));
  819.       break;
  820.  
  821.     case LOC_REGPARM:
  822.       printf ("an argument in register %s", reg_names[val]);
  823.       break;
  824.       
  825.     case LOC_ARG:
  826.       printf ("an argument at offset %ld", val);
  827.       break;
  828.  
  829.     case LOC_LOCAL_ARG:
  830.       printf ("an argument at frame offset %ld", val);
  831.       break;
  832.  
  833.     case LOC_LOCAL:
  834.       printf ("a local variable at frame offset %ld", val);
  835.       break;
  836.  
  837.     case LOC_REF_ARG:
  838.       printf ("a reference argument at offset %ld", val);
  839.       break;
  840.  
  841.     case LOC_TYPEDEF:
  842.       printf ("a typedef");
  843.       break;
  844.  
  845.     case LOC_BLOCK:
  846.       printf ("a function at address %s",
  847.           local_hex_string(BLOCK_START (SYMBOL_BLOCK_VALUE (sym))));
  848.       break;
  849.  
  850.     default:
  851.       printf ("of unknown (botched) type");
  852.       break;
  853.     }
  854.   printf (".\n");
  855. }
  856.  
  857. static void
  858. x_command (exp, from_tty)
  859.      char *exp;
  860.      int from_tty;
  861. {
  862.   struct expression *expr;
  863.   struct format_data fmt;
  864.   struct cleanup *old_chain;
  865.   struct value *val;
  866.  
  867.   fmt.format = last_format;
  868.   fmt.size = last_size;
  869.   fmt.count = 1;
  870.  
  871.   if (exp && *exp == '/')
  872.     {
  873.       exp++;
  874.       fmt = decode_format (&exp, last_format, last_size);
  875.       last_size = fmt.size;
  876.       last_format = fmt.format;
  877.     }
  878.  
  879.   /* If we have an expression, evaluate it and use it as the address.  */
  880.  
  881.   if (exp != 0 && *exp != 0)
  882.     {
  883.       expr = parse_expression (exp);
  884.       /* Cause expression not to be there any more
  885.      if this command is repeated with Newline.
  886.      But don't clobber a user-defined command's definition.  */
  887.       if (from_tty)
  888.     *exp = 0;
  889.       old_chain = make_cleanup (free_current_contents, &expr);
  890.       val = evaluate_expression (expr);
  891.       if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
  892.     val = value_ind (val);
  893.       /* In rvalue contexts, such as this, functions are coerced into
  894.      pointers to functions.  This makes "x/i main" work.  */
  895.       if (/* last_format == 'i'
  896.       && */ TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FUNC
  897.       && VALUE_LVAL (val) == lval_memory)
  898.     next_address = VALUE_ADDRESS (val);
  899.       else
  900.     next_address = value_as_pointer (val);
  901.       do_cleanups (old_chain);
  902.     }
  903.  
  904.   do_examine (fmt, next_address);
  905.  
  906.   /* Set a couple of internal variables if appropriate. */
  907.   if (last_examine_value)
  908.     {
  909.       /* Make last address examined available to the user as $_.  Use
  910.      the correct pointer type.  */
  911.       set_internalvar (lookup_internalvar ("_"),
  912.            value_from_longest (
  913.          lookup_pointer_type (VALUE_TYPE (last_examine_value)),
  914.                    (LONGEST) last_examine_address));
  915.       
  916.       /* Make contents of last address examined available to the user as $__.*/
  917.       set_internalvar (lookup_internalvar ("__"), last_examine_value);
  918.     }
  919. }
  920.  
  921. /* Commands for printing types of things.  */
  922.  
  923. /* Print type of EXP, or last thing in value history if EXP == NULL.
  924.    show is passed to type_print.  */
  925. static void
  926. whatis_exp (exp, show)
  927.      char *exp;
  928.      int show;
  929. {
  930.   struct expression *expr;
  931.   register value val;
  932.   register struct cleanup *old_chain;
  933.  
  934.   if (exp)
  935.     {
  936.       expr = parse_expression (exp);
  937.       old_chain = make_cleanup (free_current_contents, &expr);
  938.       val = evaluate_type (expr);
  939.     }
  940.   else
  941.     val = access_value_history (0);
  942.  
  943.   printf_filtered ("type = ");
  944.   type_print (VALUE_TYPE (val), "", stdout, show);
  945.   printf_filtered ("\n");
  946.  
  947.   if (exp)
  948.     do_cleanups (old_chain);
  949. }
  950.  
  951. /* ARGSUSED */
  952. static void
  953. whatis_command (exp, from_tty)
  954.      char *exp;
  955.      int from_tty;
  956. {
  957.   /* Most of the time users do not want to see all the fields
  958.      in a structure.  If they do they can use the "ptype" command.
  959.      Hence the "-1" below.  */
  960.   whatis_exp (exp, -1);
  961. }
  962.  
  963. /* Simple subroutine for ptype_command.  */
  964. static
  965. struct type *
  966. ptype_eval(exp)
  967.    struct expression *exp;
  968. {
  969.    if(exp->elts[0].opcode==OP_TYPE)
  970.       return exp->elts[1].type;
  971.    else
  972.       return 0;
  973. }
  974.  
  975. /* TYPENAME is either the name of a type, or an expression.  */
  976. /* ARGSUSED */
  977. static void
  978. ptype_command (typename, from_tty)
  979.      char *typename;
  980.      int from_tty;
  981. {
  982.   register struct type *type;
  983.   struct expression *expr;
  984.   register struct cleanup *old_chain;
  985.  
  986.   if (typename)
  987.   {
  988.      expr = parse_expression (typename);
  989.      old_chain = make_cleanup (free_current_contents, &expr);
  990.      type = ptype_eval (expr);
  991.  
  992.      if(type)
  993.      {
  994.     printf_filtered ("type = ");
  995.     type_print (type, "", stdout, 1);
  996.     printf_filtered ("\n");
  997.     do_cleanups (old_chain);
  998.      }
  999.      else
  1000.      {
  1001.     do_cleanups (old_chain);
  1002.     whatis_exp (typename, 1);
  1003.      }
  1004.   }
  1005.   else
  1006.      whatis_exp (typename, 1);
  1007. }
  1008.  
  1009. enum display_status {disabled, enabled};
  1010.  
  1011. struct display
  1012. {
  1013.   /* Chain link to next auto-display item.  */
  1014.   struct display *next;
  1015.   /* Expression to be evaluated and displayed.  */
  1016.   struct expression *exp;
  1017.   /* Item number of this auto-display item.  */
  1018.   int number;
  1019.   /* Display format specified.  */
  1020.   struct format_data format;
  1021.   /* Innermost block required by this expression when evaluated */
  1022.   struct block *block;
  1023.   /* Status of this display (enabled or disabled) */
  1024.   enum display_status status;
  1025. };
  1026.  
  1027. /* Chain of expressions whose values should be displayed
  1028.    automatically each time the program stops.  */
  1029.  
  1030. static struct display *display_chain;
  1031.  
  1032. static int display_number;
  1033.  
  1034. /* Add an expression to the auto-display chain.
  1035.    Specify the expression.  */
  1036.  
  1037. static void
  1038. display_command (exp, from_tty)
  1039.      char *exp;
  1040.      int from_tty;
  1041. {
  1042.   struct format_data fmt;
  1043.   register struct expression *expr;
  1044.   register struct display *new;
  1045.  
  1046.   if (exp == 0)
  1047.     {
  1048.       do_displays ();
  1049.       return;
  1050.     }
  1051.  
  1052.   if (*exp == '/')
  1053.     {
  1054.       exp++;
  1055.       fmt = decode_format (&exp, 0, 0);
  1056.       if (fmt.size && fmt.format == 0)
  1057.     fmt.format = 'x';
  1058.       if (fmt.format == 'i' || fmt.format == 's')
  1059.     fmt.size = 'b';
  1060.     }
  1061.   else
  1062.     {
  1063.       fmt.format = 0;
  1064.       fmt.size = 0;
  1065.       fmt.count = 0;
  1066.     }
  1067.  
  1068.   innermost_block = 0;
  1069.   expr = parse_expression (exp);
  1070.  
  1071.   new = (struct display *) xmalloc (sizeof (struct display));
  1072.  
  1073.   new->exp = expr;
  1074.   new->block = innermost_block;
  1075.   new->next = display_chain;
  1076.   new->number = ++display_number;
  1077.   new->format = fmt;
  1078.   new->status = enabled;
  1079.   display_chain = new;
  1080.  
  1081.   if (from_tty && target_has_execution)
  1082.     do_one_display (new);
  1083.  
  1084.   dont_repeat ();
  1085. }
  1086.  
  1087. static void
  1088. free_display (d)
  1089.      struct display *d;
  1090. {
  1091.   free (d->exp);
  1092.   free (d);
  1093. }
  1094.  
  1095. /* Clear out the display_chain.
  1096.    Done when new symtabs are loaded, since this invalidates
  1097.    the types stored in many expressions.  */
  1098.  
  1099. void
  1100. clear_displays ()
  1101. {
  1102.   register struct display *d;
  1103.  
  1104.   while (d = display_chain)
  1105.     {
  1106.       free (d->exp);
  1107.       display_chain = d->next;
  1108.       free (d);
  1109.     }
  1110. }
  1111.  
  1112. /* Delete the auto-display number NUM.  */
  1113.  
  1114. void
  1115. delete_display (num)
  1116.      int num;
  1117. {
  1118.   register struct display *d1, *d;
  1119.  
  1120.   if (!display_chain)
  1121.     error ("No display number %d.", num);
  1122.  
  1123.   if (display_chain->number == num)
  1124.     {
  1125.       d1 = display_chain;
  1126.       display_chain = d1->next;
  1127.       free_display (d1);
  1128.     }
  1129.   else
  1130.     for (d = display_chain; ; d = d->next)
  1131.       {
  1132.     if (d->next == 0)
  1133.       error ("No display number %d.", num);
  1134.     if (d->next->number == num)
  1135.       {
  1136.         d1 = d->next;
  1137.         d->next = d1->next;
  1138.         free_display (d1);
  1139.         break;
  1140.       }
  1141.       }
  1142. }
  1143.  
  1144. /* Delete some values from the auto-display chain.
  1145.    Specify the element numbers.  */
  1146.  
  1147. static void
  1148. undisplay_command (args)
  1149.      char *args;
  1150. {
  1151.   register char *p = args;
  1152.   register char *p1;
  1153.   register int num;
  1154.  
  1155.   if (args == 0)
  1156.     {
  1157.       if (query ("Delete all auto-display expressions? "))
  1158.     clear_displays ();
  1159.       dont_repeat ();
  1160.       return;
  1161.     }
  1162.  
  1163.   while (*p)
  1164.     {
  1165.       p1 = p;
  1166.       while (*p1 >= '0' && *p1 <= '9') p1++;
  1167.       if (*p1 && *p1 != ' ' && *p1 != '\t')
  1168.     error ("Arguments must be display numbers.");
  1169.  
  1170.       num = atoi (p);
  1171.  
  1172.       delete_display (num);
  1173.  
  1174.       p = p1;
  1175.       while (*p == ' ' || *p == '\t') p++;
  1176.     }
  1177.   dont_repeat ();
  1178. }
  1179.  
  1180. /* Display a single auto-display.  
  1181.    Do nothing if the display cannot be printed in the current context,
  1182.    or if the display is disabled. */
  1183.  
  1184. static void
  1185. do_one_display (d)
  1186.      struct display *d;
  1187. {
  1188.   int within_current_scope;
  1189.  
  1190.   if (d->status == disabled)
  1191.     return;
  1192.  
  1193.   if (d->block)
  1194.     within_current_scope = contained_in (get_selected_block (), d->block);
  1195.   else
  1196.     within_current_scope = 1;
  1197.   if (!within_current_scope)
  1198.     return;
  1199.  
  1200.   current_display_number = d->number;
  1201.  
  1202.   printf_filtered ("%d: ", d->number);
  1203.   if (d->format.size)
  1204.     {
  1205.       CORE_ADDR addr;
  1206.       
  1207.       printf_filtered ("x/");
  1208.       if (d->format.count != 1)
  1209.     printf_filtered ("%d", d->format.count);
  1210.       printf_filtered ("%c", d->format.format);
  1211.       if (d->format.format != 'i' && d->format.format != 's')
  1212.     printf_filtered ("%c", d->format.size);
  1213.       printf_filtered (" ");
  1214.       print_expression (d->exp, stdout);
  1215.       if (d->format.count != 1)
  1216.     printf_filtered ("\n");
  1217.       else
  1218.     printf_filtered ("  ");
  1219.       
  1220.       addr = value_as_pointer (evaluate_expression (d->exp));
  1221.       if (d->format.format == 'i')
  1222.     addr = ADDR_BITS_REMOVE (addr);
  1223.       
  1224.       do_examine (d->format, addr);
  1225.     }
  1226.   else
  1227.     {
  1228.       if (d->format.format)
  1229.     printf_filtered ("/%c ", d->format.format);
  1230.       print_expression (d->exp, stdout);
  1231.       printf_filtered (" = ");
  1232.       print_formatted (evaluate_expression (d->exp),
  1233.                d->format.format, d->format.size);
  1234.       printf_filtered ("\n");
  1235.     }
  1236.  
  1237.   fflush (stdout);
  1238.   current_display_number = -1;
  1239. }
  1240.  
  1241. /* Display all of the values on the auto-display chain which can be
  1242.    evaluated in the current scope.  */
  1243.  
  1244. void
  1245. do_displays ()
  1246. {
  1247.   register struct display *d;
  1248.  
  1249.   for (d = display_chain; d; d = d->next)
  1250.     do_one_display (d);
  1251. }
  1252.  
  1253. /* Delete the auto-display which we were in the process of displaying.
  1254.    This is done when there is an error or a signal.  */
  1255.  
  1256. void
  1257. disable_display (num)
  1258.      int num;
  1259. {
  1260.   register struct display *d;
  1261.  
  1262.   for (d = display_chain; d; d = d->next)
  1263.     if (d->number == num)
  1264.       {
  1265.     d->status = disabled;
  1266.     return;
  1267.       }
  1268.   printf ("No display number %d.\n", num);
  1269. }
  1270.   
  1271. void
  1272. disable_current_display ()
  1273. {
  1274.   if (current_display_number >= 0)
  1275.     {
  1276.       disable_display (current_display_number);
  1277.       fprintf (stderr, "Disabling display %d to avoid infinite recursion.\n",
  1278.            current_display_number);
  1279.     }
  1280.   current_display_number = -1;
  1281. }
  1282.  
  1283. static void
  1284. display_info ()
  1285. {
  1286.   register struct display *d;
  1287.  
  1288.   if (!display_chain)
  1289.     printf ("There are no auto-display expressions now.\n");
  1290.   else
  1291.       printf_filtered ("Auto-display expressions now in effect:\n\
  1292. Num Enb Expression\n");
  1293.  
  1294.   for (d = display_chain; d; d = d->next)
  1295.     {
  1296.       printf_filtered ("%d:   %c  ", d->number, "ny"[(int)d->status]);
  1297.       if (d->format.size)
  1298.     printf_filtered ("/%d%c%c ", d->format.count, d->format.size,
  1299.         d->format.format);
  1300.       else if (d->format.format)
  1301.     printf_filtered ("/%c ", d->format.format);
  1302.       print_expression (d->exp, stdout);
  1303.       if (d->block && !contained_in (get_selected_block (), d->block))
  1304.     printf_filtered (" (cannot be evaluated in the current context)");
  1305.       printf_filtered ("\n");
  1306.       fflush (stdout);
  1307.     }
  1308. }
  1309.  
  1310. void
  1311. enable_display (args)
  1312.      char *args;
  1313. {
  1314.   register char *p = args;
  1315.   register char *p1;
  1316.   register int num;
  1317.   register struct display *d;
  1318.  
  1319.   if (p == 0)
  1320.     {
  1321.       for (d = display_chain; d; d = d->next)
  1322.     d->status = enabled;
  1323.     }
  1324.   else
  1325.     while (*p)
  1326.       {
  1327.     p1 = p;
  1328.     while (*p1 >= '0' && *p1 <= '9')
  1329.       p1++;
  1330.     if (*p1 && *p1 != ' ' && *p1 != '\t')
  1331.       error ("Arguments must be display numbers.");
  1332.     
  1333.     num = atoi (p);
  1334.     
  1335.     for (d = display_chain; d; d = d->next)
  1336.       if (d->number == num)
  1337.         {
  1338.           d->status = enabled;
  1339.           goto win;
  1340.         }
  1341.     printf ("No display number %d.\n", num);
  1342.       win:
  1343.     p = p1;
  1344.     while (*p == ' ' || *p == '\t')
  1345.       p++;
  1346.       }
  1347. }
  1348.  
  1349. /* ARGSUSED */
  1350. void
  1351. disable_display_command (args, from_tty)
  1352.      char *args;
  1353.      int from_tty;
  1354. {
  1355.   register char *p = args;
  1356.   register char *p1;
  1357.   register struct display *d;
  1358.  
  1359.   if (p == 0)
  1360.     {
  1361.       for (d = display_chain; d; d = d->next)
  1362.     d->status = disabled;
  1363.     }
  1364.   else
  1365.     while (*p)
  1366.       {
  1367.     p1 = p;
  1368.     while (*p1 >= '0' && *p1 <= '9')
  1369.       p1++;
  1370.     if (*p1 && *p1 != ' ' && *p1 != '\t')
  1371.       error ("Arguments must be display numbers.");
  1372.     
  1373.     disable_display (atoi (p));
  1374.  
  1375.     p = p1;
  1376.     while (*p == ' ' || *p == '\t')
  1377.       p++;
  1378.       }
  1379. }
  1380.  
  1381.  
  1382. /* Print the value in stack frame FRAME of a variable
  1383.    specified by a struct symbol.  */
  1384.  
  1385. void
  1386. print_variable_value (var, frame, stream)
  1387.      struct symbol *var;
  1388.      FRAME frame;
  1389.      FILE *stream;
  1390. {
  1391.   value val = read_var_value (var, frame);
  1392.   value_print (val, stream, 0, Val_pretty_default);
  1393. }
  1394.  
  1395. /* Print the arguments of a stack frame, given the function FUNC
  1396.    running in that frame (as a symbol), the info on the frame,
  1397.    and the number of args according to the stack frame (or -1 if unknown).  */
  1398.  
  1399. /* References here and elsewhere to "number of args according to the
  1400.    stack frame" appear in all cases to refer to "number of ints of args
  1401.    according to the stack frame".  At least for VAX, i386, isi.  */
  1402.  
  1403. void
  1404. print_frame_args (func, fi, num, stream)
  1405.      struct symbol *func;
  1406.      struct frame_info *fi;
  1407.      int num;
  1408.      FILE *stream;
  1409. {
  1410.   struct block *b;
  1411.   int nsyms = 0;
  1412.   int first = 1;
  1413.   register int i;
  1414.   register struct symbol *sym;
  1415.   register value val;
  1416.   /* Offset of next stack argument beyond the one we have seen that is
  1417.      at the highest offset.
  1418.      -1 if we haven't come to a stack argument yet.  */
  1419.   long highest_offset = -1;
  1420.   int arg_size;
  1421.   /* Number of ints of arguments that we have printed so far.  */
  1422.   int args_printed = 0;
  1423.  
  1424.   if (func)
  1425.     {
  1426.       b = SYMBOL_BLOCK_VALUE (func);
  1427.       nsyms = BLOCK_NSYMS (b);
  1428.     }
  1429.  
  1430.   for (i = 0; i < nsyms; i++)
  1431.     {
  1432.       QUIT;
  1433.       sym = BLOCK_SYM (b, i);
  1434.  
  1435.       /* Keep track of the highest stack argument offset seen, and
  1436.      skip over any kinds of symbols we don't care about.  */
  1437.  
  1438.       switch (SYMBOL_CLASS (sym)) {
  1439.       case LOC_ARG:
  1440.       case LOC_REF_ARG:
  1441.     {
  1442.       long current_offset = SYMBOL_VALUE (sym);
  1443.  
  1444.       arg_size = TYPE_LENGTH (SYMBOL_TYPE (sym));
  1445.       
  1446.       /* Compute address of next argument by adding the size of
  1447.          this argument and rounding to an int boundary.  */
  1448.       current_offset
  1449.         = ((current_offset + arg_size + sizeof (int) - 1)
  1450.            & ~(sizeof (int) - 1));
  1451.  
  1452.       /* If this is the highest offset seen yet, set highest_offset.  */
  1453.       if (highest_offset == -1
  1454.           || (current_offset > highest_offset))
  1455.         highest_offset = current_offset;
  1456.  
  1457.       /* Add the number of ints we're about to print to args_printed.  */
  1458.       args_printed += (arg_size + sizeof (int) - 1) / sizeof (int);
  1459.     }
  1460.  
  1461.       /* We care about types of symbols, but don't need to keep track of
  1462.      stack offsets in them.  */
  1463.       case LOC_REGPARM:
  1464.       case LOC_LOCAL_ARG:
  1465.     break;
  1466.  
  1467.       /* Other types of symbols we just skip over.  */
  1468.       default:
  1469.     continue;
  1470.       }
  1471.  
  1472.       /* We have to re-look-up the symbol because arguments often have
  1473.      two entries (one a parameter, one a register or local), and the one
  1474.      we want is the non-parm, which lookup_symbol will find for
  1475.      us.  After this, sym could be any SYMBOL_CLASS...  */
  1476.       sym = lookup_symbol (SYMBOL_NAME (sym),
  1477.             b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
  1478.  
  1479.       /* Print the current arg.  */
  1480.       if (! first)
  1481.     fprintf_filtered (stream, ", ");
  1482.       wrap_here ("    ");
  1483.       fprint_symbol (stream, SYMBOL_NAME (sym));
  1484.       fputs_filtered ("=", stream);
  1485.  
  1486.       /* Avoid value_print because it will deref ref parameters.  We just
  1487.      want to print their addresses.  Print ??? for args whose address
  1488.      we do not know.  We pass 2 as "recurse" to val_print because our
  1489.      standard indentation here is 4 spaces, and val_print indents
  1490.      2 for each recurse.  */
  1491.       val = read_var_value (sym, FRAME_INFO_ID (fi));
  1492.       if (val)
  1493.         val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val),
  1494.            stream, 0, 0, 2, Val_no_prettyprint);
  1495.       else
  1496.     fputs_filtered ("???", stream);
  1497.       first = 0;
  1498.     }
  1499.  
  1500.   /* Don't print nameless args in situations where we don't know
  1501.      enough about the stack to find them.  */
  1502.   if (num != -1)
  1503.     {
  1504.       long start;
  1505.       CORE_ADDR addr;
  1506.  
  1507.       if (highest_offset == -1)
  1508.     start = FRAME_ARGS_SKIP;
  1509.       else
  1510.     start = highest_offset;
  1511.  
  1512.       addr = FRAME_ARGS_ADDRESS (fi);
  1513.       if (addr)
  1514.         print_frame_nameless_args (addr, start, num - args_printed,
  1515.                    first, stream);
  1516.     }
  1517. }
  1518.  
  1519. /* Print nameless args on STREAM.
  1520.    ARGSADDR is the address of the arglist, START is the offset
  1521.    of the first nameless arg, and NUM is the number of nameless args to
  1522.    print.  FIRST is nonzero if this is the first argument (not just
  1523.    the first nameless arg).  */
  1524. static void
  1525. print_frame_nameless_args (argsaddr, start, num, first, stream)
  1526.      CORE_ADDR argsaddr;
  1527.      long start;
  1528.      int num;
  1529.      int first;
  1530.      FILE *stream;
  1531. {
  1532.   int i;
  1533.   for (i = 0; i < num; i++)
  1534.     {
  1535.       QUIT;
  1536.       if (!first)
  1537.     fprintf_filtered (stream, ", ");
  1538. #ifndef PRINT_TYPELESS_INTEGER
  1539.       fprintf_filtered (stream, "%d",
  1540.            read_memory_integer (argsaddr + start, sizeof (int)));
  1541. #else
  1542.       PRINT_TYPELESS_INTEGER (stream, builtin_type_int,
  1543.                   (LONGEST)
  1544.                   read_memory_integer (argsaddr + start,
  1545.                            sizeof (int)));
  1546. #endif
  1547.       first = 0;
  1548.       start += sizeof (int);
  1549.     }
  1550. }
  1551.  
  1552. /* ARGSUSED */
  1553. static void
  1554. printf_command (arg, from_tty)
  1555.      char *arg;
  1556.      int from_tty;
  1557. {
  1558.   register char *f;
  1559.   register char *s = arg;
  1560.   char *string;
  1561.   value *val_args;
  1562.   int nargs = 0;
  1563.   int allocated_args = 20;
  1564.   char *arg_bytes;
  1565.  
  1566.   val_args = (value *) xmalloc (allocated_args * sizeof (value));
  1567.  
  1568.   if (s == 0)
  1569.     error_no_arg ("format-control string and values to print");
  1570.  
  1571.   /* Skip white space before format string */
  1572.   while (*s == ' ' || *s == '\t') s++;
  1573.  
  1574.   /* A format string should follow, enveloped in double quotes */
  1575.   if (*s++ != '"')
  1576.     error ("Bad format string, missing '\"'.");
  1577.  
  1578.   /* Parse the format-control string and copy it into the string STRING,
  1579.      processing some kinds of escape sequence.  */
  1580.  
  1581.   f = string = (char *) alloca (strlen (s) + 1);
  1582.   while (*s != '"')
  1583.     {
  1584.       int c = *s++;
  1585.       switch (c)
  1586.     {
  1587.     case '\0':
  1588.       error ("Bad format string, non-terminated '\"'.");
  1589.       /* doesn't return */
  1590.  
  1591.     case '\\':
  1592.       switch (c = *s++)
  1593.         {
  1594.         case '\\':
  1595.           *f++ = '\\';
  1596.           break;
  1597.         case 'n':
  1598.           *f++ = '\n';
  1599.           break;
  1600.         case 't':
  1601.           *f++ = '\t';
  1602.           break;
  1603.         case 'r':
  1604.           *f++ = '\r';
  1605.           break;
  1606.         case '"':
  1607.           *f++ = '"';
  1608.           break;
  1609.         default:
  1610.           /* ??? TODO: handle other escape sequences */
  1611.           error ("Unrecognized \\ escape character in format string.");
  1612.         }
  1613.       break;
  1614.  
  1615.     default:
  1616.       *f++ = c;
  1617.     }
  1618.     }
  1619.  
  1620.   /* Skip over " and following space and comma.  */
  1621.   s++;
  1622.   *f++ = '\0';
  1623.   while (*s == ' ' || *s == '\t') s++;
  1624.  
  1625.   if (*s != ',' && *s != 0)
  1626.     error ("Invalid argument syntax");
  1627.  
  1628.   if (*s == ',') s++;
  1629.   while (*s == ' ' || *s == '\t') s++;
  1630.  
  1631.   {
  1632.     /* Now scan the string for %-specs and see what kinds of args they want.
  1633.        argclass[I] classifies the %-specs so we can give vprintf something
  1634.        of the right size.  */
  1635.  
  1636.     enum argclass {int_arg, string_arg, double_arg, long_long_arg};
  1637.     enum argclass *argclass;
  1638.     int nargs_wanted;
  1639.     int argindex;
  1640.     int lcount;
  1641.     int i;
  1642.  
  1643.     argclass = (enum argclass *) alloca (strlen (s) * sizeof *argclass);
  1644.     nargs_wanted = 0;
  1645.     f = string;
  1646.     while (*f)
  1647.       if (*f++ == '%')
  1648.     {
  1649.       lcount = 0;
  1650.       while (strchr ("0123456789.hlL-+ #", *f)) 
  1651.         {
  1652.           if (*f == 'l' || *f == 'L')
  1653.         lcount++;
  1654.           f++;
  1655.         }
  1656.       if (*f == 's')
  1657.         argclass[nargs_wanted++] = string_arg;
  1658.       else if (*f == 'e' || *f == 'f' || *f == 'g')
  1659.         argclass[nargs_wanted++] = double_arg;
  1660.       else if (lcount > 1)
  1661.         argclass[nargs_wanted++] = long_long_arg;
  1662.       else if (*f != '%')
  1663.         argclass[nargs_wanted++] = int_arg;
  1664.       f++;
  1665.     }
  1666.  
  1667.     /* Now, parse all arguments and evaluate them.
  1668.        Store the VALUEs in VAL_ARGS.  */
  1669.  
  1670.     while (*s != '\0')
  1671.       {
  1672.     char *s1;
  1673.     if (nargs == allocated_args)
  1674.       val_args = (value *) xrealloc (val_args,
  1675.                      (allocated_args *= 2)
  1676.                      * sizeof (value));
  1677.     s1 = s;
  1678.     val_args[nargs] = parse_to_comma_and_eval (&s1);
  1679.  
  1680.     /* If format string wants a float, unchecked-convert the value to
  1681.        floating point of the same size */
  1682.  
  1683.     if (argclass[nargs] == double_arg)
  1684.       {
  1685.         if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (float))
  1686.           VALUE_TYPE (val_args[nargs]) = builtin_type_float;
  1687.         if (TYPE_LENGTH (VALUE_TYPE (val_args[nargs])) == sizeof (double))
  1688.           VALUE_TYPE (val_args[nargs]) = builtin_type_double;
  1689.       }
  1690.     nargs++;
  1691.     s = s1;
  1692.     if (*s == ',')
  1693.       s++;
  1694.       }
  1695.  
  1696.     if (nargs != nargs_wanted)
  1697.       error ("Wrong number of arguments for specified format-string");
  1698.  
  1699.     /* Now lay out an argument-list containing the arguments
  1700.        as doubles, integers and C pointers.  */
  1701.  
  1702.     arg_bytes = (char *) alloca (sizeof (double) * nargs);
  1703.     argindex = 0;
  1704.     for (i = 0; i < nargs; i++)
  1705.       {
  1706.     if (argclass[i] == string_arg)
  1707.       {
  1708.         char *str;
  1709.         CORE_ADDR tem;
  1710.         int j;
  1711.         tem = value_as_pointer (val_args[i]);
  1712.  
  1713.         /* This is a %s argument.  Find the length of the string.  */
  1714.         for (j = 0; ; j++)
  1715.           {
  1716.         char c;
  1717.         QUIT;
  1718.         read_memory (tem + j, &c, 1);
  1719.         if (c == 0)
  1720.           break;
  1721.           }
  1722.  
  1723.         /* Copy the string contents into a string inside GDB.  */
  1724.         str = (char *) alloca (j + 1);
  1725.         read_memory (tem, str, j);
  1726.         str[j] = 0;
  1727.  
  1728.         /* Pass address of internal copy as the arg to vprintf.  */
  1729.         *((int *) &arg_bytes[argindex]) = (int) str;
  1730.         argindex += sizeof (int);
  1731.       }
  1732.     else if (VALUE_TYPE (val_args[i])->code == TYPE_CODE_FLT)
  1733.       {
  1734.         *((double *) &arg_bytes[argindex]) = value_as_double (val_args[i]);
  1735.         argindex += sizeof (double);
  1736.       }
  1737.     else
  1738. #ifdef LONG_LONG
  1739.       if (argclass[i] == long_long_arg)
  1740.         {
  1741.           *(long long *) &arg_bytes[argindex] = value_as_long (val_args[i]);
  1742.           argindex += sizeof (long long);
  1743.         }
  1744.       else
  1745. #endif
  1746.         {
  1747.           *((long *) &arg_bytes[argindex]) = value_as_long (val_args[i]);
  1748.           argindex += sizeof (long);
  1749.         }
  1750.       }
  1751.   }
  1752.  
  1753.   /* There is not a standard way to make a va_list, so we need
  1754.      to do various things for different systems.  */
  1755. #if defined (__INT_VARARGS_H)
  1756.   {
  1757.     va_list list;
  1758.  
  1759.     list.__va_arg = 0;
  1760.     list.__va_stk = (int *) arg_bytes;
  1761.     list.__va_reg = (int *) arg_bytes;
  1762.     vprintf (string, list);
  1763.   }
  1764. #else /* No __INT_VARARGS_H.  */
  1765.   vprintf (string, arg_bytes);
  1766. #endif /* No __INT_VARARGS_H.  */
  1767. }
  1768.  
  1769. /* Helper function for asdump_command.  Finds the bounds of a function
  1770.    for a specified section of text.  PC is an address within the
  1771.    function which you want bounds for; *LOW and *HIGH are set to the
  1772.    beginning (inclusive) and end (exclusive) of the function.  This
  1773.    function returns 1 on success and 0 on failure.  */
  1774.  
  1775. static int
  1776. containing_function_bounds (pc, low, high)
  1777.      CORE_ADDR pc, *low, *high;
  1778. {
  1779.   int scan;
  1780.  
  1781.   if (!find_pc_partial_function (pc, 0, low))
  1782.     return 0;
  1783.  
  1784.   scan = *low;
  1785.   do {
  1786.     scan++;
  1787.     if (!find_pc_partial_function (scan, 0, high))
  1788.       return 0;
  1789.   } while (*low == *high);
  1790.  
  1791.   return 1;
  1792. }
  1793.  
  1794. /* Dump a specified section of assembly code.  With no command line
  1795.    arguments, this command will dump the assembly code for the
  1796.    function surrounding the pc value in the selected frame.  With one
  1797.    argument, it will dump the assembly code surrounding that pc value.
  1798.    Two arguments are interpeted as bounds within which to dump
  1799.    assembly.  */
  1800.  
  1801. /* ARGSUSED */
  1802. static void
  1803. disassemble_command (arg, from_tty)
  1804.      char *arg;
  1805.      int from_tty;
  1806. {
  1807.   CORE_ADDR low, high;
  1808.   CORE_ADDR pc;
  1809.   char *space_index;
  1810.  
  1811.   if (!arg)
  1812.     {
  1813.       if (!selected_frame)
  1814.     error ("No frame selected.\n");
  1815.  
  1816.       pc = get_frame_pc (selected_frame);
  1817.       if (!containing_function_bounds (pc, &low, &high))
  1818.     error ("No function contains pc specified by selected frame.\n");
  1819.     }
  1820.   else if (!(space_index = (char *) strchr (arg, ' ')))
  1821.     {
  1822.       /* One argument.  */
  1823.       pc = parse_and_eval_address (arg);
  1824.       if (!containing_function_bounds (pc, &low, &high))
  1825.     error ("No function contains specified pc.\n");
  1826.     }
  1827.   else
  1828.     {
  1829.       /* Two arguments.  */
  1830.       *space_index = '\0';
  1831.       low = parse_and_eval_address (arg);
  1832.       high = parse_and_eval_address (space_index + 1);
  1833.     }
  1834.  
  1835.   printf_filtered ("Dump of assembler code ");
  1836.   if (!space_index)
  1837.     {
  1838.       char *name;
  1839.       find_pc_partial_function (pc, &name, 0);
  1840.       printf_filtered ("for function %s:\n", name);
  1841.     }
  1842.   else
  1843.     printf_filtered ("from %s ", local_hex_string(low));
  1844.     printf_filtered ("to %s:\n", local_hex_string(high));
  1845.  
  1846.   /* Dump the specified range.  */
  1847.   for (pc = low; pc < high; )
  1848.     {
  1849.       QUIT;
  1850.       print_address (pc, stdout);
  1851.       printf_filtered (":\t");
  1852.       pc += print_insn (pc, stdout);
  1853.       printf_filtered ("\n");
  1854.     }
  1855.   printf_filtered ("End of assembler dump.\n");
  1856.   fflush (stdout);
  1857. }
  1858.  
  1859.  
  1860. void
  1861. _initialize_printcmd ()
  1862. {
  1863.   current_display_number = -1;
  1864.  
  1865.   add_info ("address", address_info,
  1866.        "Describe where variable VAR is stored.");
  1867.  
  1868.   add_com ("x", class_vars, x_command,
  1869.        "Examine memory: x/FMT ADDRESS.\n\
  1870. ADDRESS is an expression for the memory address to examine.\n\
  1871. FMT is a repeat count followed by a format letter and a size letter.\n\
  1872. Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),\n\
  1873.  f(float), a(address), i(instruction), c(char) and s(string).\n\
  1874. Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).\n\
  1875.   g is meaningful only with f, for type double.\n\
  1876. The specified number of objects of the specified size are printed\n\
  1877. according to the format.\n\n\
  1878. Defaults for format and size letters are those previously used.\n\
  1879. Default count is 1.  Default address is following last thing printed\n\
  1880. with this command or \"print\".");
  1881.  
  1882.   add_com ("disassemble", class_vars, disassemble_command,
  1883.        "Disassemble a specified section of memory.\n\
  1884. Default is the function surrounding the pc of the selected frame.\n\
  1885. With a single argument, the function surrounding that address is dumped.\n\
  1886. Two arguments are taken as a range of memory to dump.");
  1887.  
  1888.   add_com ("ptype", class_vars, ptype_command,
  1889.        "Print definition of type TYPE.\n\
  1890. Argument may be a type name defined by typedef, or \"struct STRUCTNAME\"\n\
  1891. or \"union UNIONNAME\" or \"enum ENUMNAME\".\n\
  1892. The selected stack frame's lexical context is used to look up the name.");
  1893.  
  1894.   add_com ("whatis", class_vars, whatis_command,
  1895.        "Print data type of expression EXP.");
  1896.  
  1897. #if 0
  1898.   add_com ("whereis", class_vars, whereis_command,
  1899.        "Print line number and file of definition of variable.");
  1900. #endif
  1901.   
  1902.   add_info ("display", display_info,
  1903.         "Expressions to display when program stops, with code numbers.");
  1904.  
  1905.   add_cmd ("undisplay", class_vars, undisplay_command,
  1906.        "Cancel some expressions to be displayed when program stops.\n\
  1907. Arguments are the code numbers of the expressions to stop displaying.\n\
  1908. No argument means cancel all automatic-display expressions.\n\
  1909. \"delete display\" has the same effect as this command.\n\
  1910. Do \"info display\" to see current list of code numbers.",
  1911.           &cmdlist);
  1912.  
  1913.   add_com ("display", class_vars, display_command,
  1914.        "Print value of expression EXP each time the program stops.\n\
  1915. /FMT may be used before EXP as in the \"print\" command.\n\
  1916. /FMT \"i\" or \"s\" or including a size-letter is allowed,\n\
  1917. as in the \"x\" command, and then EXP is used to get the address to examine\n\
  1918. and examining is done as in the \"x\" command.\n\n\
  1919. With no argument, display all currently requested auto-display expressions.\n\
  1920. Use \"undisplay\" to cancel display requests previously made.");
  1921.  
  1922.   add_cmd ("display", class_vars, enable_display, 
  1923.        "Enable some expressions to be displayed when program stops.\n\
  1924. Arguments are the code numbers of the expressions to resume displaying.\n\
  1925. No argument means enable all automatic-display expressions.\n\
  1926. Do \"info display\" to see current list of code numbers.", &enablelist);
  1927.  
  1928.   add_cmd ("display", class_vars, disable_display_command, 
  1929.        "Disable some expressions to be displayed when program stops.\n\
  1930. Arguments are the code numbers of the expressions to stop displaying.\n\
  1931. No argument means disable all automatic-display expressions.\n\
  1932. Do \"info display\" to see current list of code numbers.", &disablelist);
  1933.  
  1934.   add_cmd ("display", class_vars, undisplay_command, 
  1935.        "Cancel some expressions to be displayed when program stops.\n\
  1936. Arguments are the code numbers of the expressions to stop displaying.\n\
  1937. No argument means cancel all automatic-display expressions.\n\
  1938. Do \"info display\" to see current list of code numbers.", &deletelist);
  1939.  
  1940.   add_com ("printf", class_vars, printf_command,
  1941.     "printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\
  1942. This is useful for formatted output in user-defined commands.");
  1943.   add_com ("output", class_vars, output_command,
  1944.        "Like \"print\" but don't put in value history and don't print newline.\n\
  1945. This is useful in user-defined commands.");
  1946.  
  1947.   add_prefix_cmd ("set", class_vars, set_command,
  1948. "Perform an assignment VAR = EXP.\n\
  1949. You must type the \"=\".  VAR may be a debugger \"convenience\" variable\n\
  1950. (names starting with $), a register (a few standard names starting with $),\n\
  1951. or an actual variable in the program being debugged.  EXP is any expression.\n\
  1952. Use \"set variable\" for variables with names identical to set subcommands.\n\
  1953. \nWith a subcommand, this command modifies parts of the gdb environment.\n\
  1954. You can see these environment settings with the \"show\" command.",
  1955.                   &setlist, "set ", 1, &cmdlist);
  1956.  
  1957.   /* "call" is the same as "set", but handy for dbx users to call fns. */
  1958.   add_com ("call", class_vars, call_command,
  1959.        "Call a function in the inferior process.\n\
  1960. The argument is the function name and arguments, in the notation of the\n\
  1961. current working language.  The result is printed and saved in the value\n\
  1962. history, if it is not void.");
  1963.  
  1964.   add_cmd ("variable", class_vars, set_command,
  1965.            "Perform an assignment VAR = EXP.\n\
  1966. You must type the \"=\".  VAR may be a debugger \"convenience\" variable\n\
  1967. (names starting with $), a register (a few standard names starting with $),\n\
  1968. or an actual variable in the program being debugged.  EXP is any expression.\n\
  1969. This may usually be abbreviated to simply \"set\".",
  1970.            &setlist);
  1971.  
  1972.   add_com ("print", class_vars, print_command,
  1973.        concat ("Print value of expression EXP.\n\
  1974. Variables accessible are those of the lexical environment of the selected\n\
  1975. stack frame, plus all those whose scope is global or an entire file.\n\
  1976. \n\
  1977. $NUM gets previous value number NUM.  $ and $$ are the last two values.\n\
  1978. $$NUM refers to NUM'th value back from the last one.\n\
  1979. Names starting with $ refer to registers (with the values they would have\n\
  1980. if the program were to return to the stack frame now selected, restoring\n\
  1981. all registers saved by frames farther in) or else to debugger\n\
  1982. \"convenience\" variables (any such name not a known register).\n\
  1983. Use assignment expressions to give values to convenience variables.\n",
  1984.            "\n\
  1985. {TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.\n\
  1986. @ is a binary operator for treating consecutive data objects\n\
  1987. anywhere in memory as an array.  FOO@NUM gives an array whose first\n\
  1988. element is FOO, whose second element is stored in the space following\n\
  1989. where FOO is stored, etc.  FOO must be an expression whose value\n\
  1990. resides in memory.\n",
  1991.            "\n\
  1992. EXP may be preceded with /FMT, where FMT is a format letter\n\
  1993. but no count or size letter (see \"x\" command)."));
  1994.   add_com_alias ("p", "print", class_vars, 1);
  1995.  
  1996.   add_com ("inspect", class_vars, inspect_command,
  1997. "Same as \"print\" command, except that if you are running in the epoch\n\
  1998. environment, the value is printed in its own window.");
  1999. }
  2000.